package com.mayihr.fx.one_;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class L3_learn_login_gridpane_css extends Application {
    public void start(Stage primaryStage) throws Exception {
        GridPane gridPane = new GridPane();//表格容器
        gridPane.setAlignment(Pos.CENTER);//居中
        gridPane.setHgap(10);//间隙 竖宽
        gridPane.setVgap(10);//间隙 行宽
        gridPane.setPadding(new Insets(25, 25, 25, 25));//填充空白 上、右、下、左

        Scene scene = new Scene(gridPane, 300, 200); //窗口容器 包装表格容器
        primaryStage.setScene(scene); //添加主要界面
        scene.getStylesheets().add(getClass().getResource("/Login.css").toExternalForm());
        primaryStage.show();//显示

        Text scenetitle = new Text("WelCome");
        scenetitle.setId("welcome-text");
//        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL,20));
        gridPane.add(scenetitle, 0, 0, 2, 1);//0行0列 占用2列1行

        Label username = new Label("User Name:");
        gridPane.add(username,0,1);//0行1列

        TextField userTextField = new TextField();
        gridPane.add(userTextField,1,1);

        Label password = new Label("PassWorld:");
        gridPane.add(password,0,2);

        PasswordField pwTx = new PasswordField();
        gridPane.add(pwTx, 1, 2);

        Button btn = new Button("Sign in");
        HBox hbBtn = new HBox(10);
        hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
        hbBtn.getChildren().add(btn);
        gridPane.add(hbBtn, 1, 4);

        final Text actiontarget = new Text();
        gridPane.add(actiontarget, 1, 6);
        actiontarget.setId("actiontarget");

        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e) {
//                actiontarget.setFill(Color.FIREBRICK);
                actiontarget.setText("Sign in button pressed");
            }
        });
    }

    public static void main(String args[]) {
        launch(args);
    }
}

